# 网易邮箱发送邮件
import os
import time
from selenium import webdriver
# 用加载配置信息打开163邮箱网页
# 1.实例化配置类
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
# 2.准备配置项
user_data_dir = r'--user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data'
# 添加配置
options.add_argument(user_data_dir)
driver = webdriver.Chrome(options=options)
driver.get("https://mail.163.com")
# 点击写信输入信息
# 1.进入写信页面
driver.find_element(By.ID, '_mail_component_149_149').click()
# 2.定位收件人输入框输入内容
driver.find_element(By.CLASS_NAME, "nui-editableAddr-ipt").send_keys("948879744@qq.com")
# 3.定位主题输入框输入内容
driver.find_element(By.XPATH, "//*[contains(@id, 'subjectInput')]").send_keys("这是一个悲伤的故事")
# 4.编辑上传文件路径，定位上传按钮上传文件
file =os.path.join(os.path.abspath("./html/popup.html"))
driver.find_element(By.CLASS_NAME, "O0").send_keys(file)
# 5.定位文本输入框输入文本内容
frame1 = driver.find_element(By.CLASS_NAME, 'APP-editor-iframe')
driver.switch_to.frame(frame1)
driver.find_element(By.CSS_SELECTOR, "P[style='margin:0;']").send_keys("一场悲剧的开始总是平平无奇")
# 6.回到主文本定位发送并点击
driver.switch_to.default_content()
driver.find_element(By.XPATH, "//footer/div/span[2]").click()
# 关闭网页
time.sleep(3)
driver.quit()
